%{
	#include "y.tab.h"
	#include <stdio.h>
	#include <stdlib.h>
	#include <string.h>
	#include "../tableSymbole/hashTable.h"
	#include "tableGencode.h"
	#include "tableValueText.h"
	
	char * charTemp;
	extern int yylval;
	extern int erreurCompilation;
	extern int commentaires;	
%}

%s COMMENTAIRE NORMAL

chiffre [0-9]
lettreMin [a-z]
lettreMaj [A-Z]
lettre {lettreMin}|{lettreMaj}
caractere {lettre}|{chiffre}|['_]
entier {chiffre}+
blanc " "|"\t"|"\r"|"\n"
identifiant {lettre}{caractere}*

%%
%{
	BEGIN NORMAL;
%}


<NORMAL>"write" {return WRITE;}
<NORMAL>"var" {return VAR;}
<NORMAL>"int" {return INT;}
<NORMAL>"bool" {return BOOLEEN;}
<NORMAL>"not" {return NOT;}
<NORMAL>"or" {return OR;}
<NORMAL>"and" {return AND;}
<NORMAL>"xor" {return XOR;}
<NORMAL>"if" {return IF;}
<NORMAL>"then" {return THEN;}
<NORMAL>"else" {return ELSE;}
<NORMAL>"unit" {return UNIT;}
<NORMAL>"function" {return FUNCTION;}
<NORMAL>"return" {return RETURN;}
<NORMAL>"program" {return PROGRAM;}
<NORMAL>"read" {return READ;}
<NORMAL>"begin" {return TOKENBEGIN;}
<NORMAL>"end" {return TOKENEND;}
<NORMAL>"while" {return WHILE;}
<NORMAL>"do" {return DO;}
<NORMAL>"true" {yylval = 1; return BOOL;}
<NORMAL>"false" {yylval = 0; return BOOL;}
<NORMAL>"+" {return PLUS;}
<NORMAL>"*" {return FOIS;}
<NORMAL>"-" {return MOINS;}
<NORMAL>"/" {return DIVISER;}
<NORMAL>"^" {return POW;}
<NORMAL>"(" {return PGAUCHE;}
<NORMAL>")" {return PDROITE;}
<NORMAL>":=" {return AFFECTATION;}
<NORMAL>";" {return POINTVIRGULE;}
<NORMAL>"," {return VIRGULE;}
<NORMAL>":" {return DEUXPOINTS;}
<NORMAL>"<" {return PPETITS;}
<NORMAL>">" {return PGRANDS;}
<NORMAL>"<=" {return PPETIT;}
<NORMAL>">=" {return PGRAND;}
<NORMAL>"=" {return EGAL;}
<NORMAL>"<>" {return DIFFERENT;}
<NORMAL>{entier} {yylval = atoi(yytext); return ENTIER;}

<NORMAL>{identifiant} {charTemp = calloc(strlen(yytext) + 6,sizeof(char));sprintf(charTemp,"_User%s",yytext);yylval = ajoutTableValueText(charTemp);if(yylval == -1){printf("Erreur : lex : table valeur text pleine.\n");erreurCompilation = 1;}return IDENTIFIANT;}
<NORMAL>\".*\" {charTemp = calloc(strlen(yytext)+1,sizeof(char));strcpy(charTemp,yytext);yylval = ajoutTableValueText(charTemp); if(yylval == -1) {printf("Erreur : lex : table valeur text pleine.\n"); erreurCompilation = 1;} return STRING;}
<NORMAL>{blanc}

<NORMAL>"(*"  {commentaires++; BEGIN COMMENTAIRE;}
<NORMAL>.|\n  {}

<COMMENTAIRE>"(*"                {commentaires++;}
<COMMENTAIRE>.|\n                {}
<COMMENTAIRE>"*)"                {if (--commentaires==0) BEGIN NORMAL;}

